#ifndef CUSTOMTHREAD_H
#define CUSTOMTHREAD_H

#include <QThread>
#include <qDebug>
#include <QNetworkReply>
#include <QFile>

class WorkObject : public QObject
{
    Q_OBJECT
public:

    WorkObject(QObject *parent = Q_NULLPTR);
    ~WorkObject();

    void SetWorkInfo(QString DowURL, QString LocalPath, QString Md5)
    {
        URL = DowURL;
        LocalFilePath = LocalPath;
        OMd5 = Md5;
    }

public slots:
    void WorkStart();
    void OnHttpError(QNetworkReply::NetworkError Error);
    void HttpProgress(qint64 NowLen, qint64 FileLen);
    void HttpDowloading();
    void HttpDowloadFinished();

signals:
    void EmitWorkError(QNetworkReply::NetworkError Error);
    void EmitWorkProgress(qint64 NowLen, qint64 FileLen);
    void EmitWorkFinished();

    void EmitCheckMd5Yes();
    void EmitNotOpenFile();
    void EmitBeginHttpTimer();

private:
    QNetworkReply* WorkReply;
    QFile* HttpFile;
    QString URL;
    QString LocalFilePath;     //本地的文件
    QString OMd5;                //从配置获取的MD5值
    bool DowError;                  //下载错误
};

class InitThread : public QThread
{
    Q_OBJECT

public:
    InitThread() {}
    virtual ~InitThread() {}
    virtual void run();

signals:
    void SendMainConfig(QString Ip, quint16 Port);
};

#endif
